<template>
  <div>
    <div v-if="!show">
      没有找到结果
    </div>
    <Result v-if="show" v-loading="loading" :data="data" />
  </div>
</template>

<script>
import { getDetail } from '../../../api/query-log'

export default {
  name: 'QueryLogView',
  components: {
    Result: () => import('../generate/result')
  },
  data() {
    return {
      loading: false,
      show: false,
      data: {
        sy_majors: [],
        remark: '',
        academyScores: [],
        intention_majors: [],
        intention_colleges: [],
        exclude_majors: [],
        exclude_colleges: [],
        predilection: {},
        result: {
          academy: '[]',
          major: '[]',
          balance: '[]',
          user: {}
        }
      }
    }
  },
  mounted() {
    this.getDetail(this.$route.params.id)
  },
  methods: {
    getDetail(id) {
      this.loading = true
      const loading = this.$loading({
        lock: true,
        text: '玩儿命加载中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      getDetail(id).then((res) => {
        const data = Object.assign({}, this.data)
        data['result']['academy'] = JSON.stringify(res.result.academy)
        data['result']['major'] = JSON.stringify(res.result.major)
        data['result']['balance'] = JSON.stringify(res.result.balance)
        data['result']['user'] = {
          level: res.condition.target,
          division: res.condition.subject_category,
          sex: res.condition.gender,
          score: res.condition.score,
          precedence: res.condition.rank,
          province: res.condition.province
        }
        data['academyScores'] = res.scores
        data['remark'] = res.condition.remark
        data['intention_colleges'] = res.intention_colleges
        data['intention_majors'] = res.intention_majors
        data['exclude_majors'] = res.exclude_majors
        data['exclude_colleges'] = res.exclude_colleges
        data['predilection']['area'] = res.condition.intended_region.join('、')
        data['predilection']['exclude_area'] = res.condition.except_province.join('、')
        this.data = data
        this.show = true
      }).finally(() => {
        this.loading = false
        loading.close()
      })
    }
  }
}
</script>

<style scoped>

</style>
